package com.tuxing.draa_data.service;

import com.google.common.base.Strings;
import com.tuxing.draa_data.dao.center.NewDcBibliographyBookDao;
import com.tuxing.draa_data.dao.center.NewDcBibliographyPeriDao;
import com.tuxing.draa_data.pojo.center.NewDcBibliographyBook;
import com.tuxing.draa_data.pojo.center.NewDcBibliographyPeri;

import javax.annotation.Resource;

/**
 * @author yuanshihang
 * @version 1.0
 * @className BaseService
 * @description 基础描述: 基础查询等
 * @date 2022/6/28 17:25
 */
public abstract class BaseService {

    @Resource
    private NewDcBibliographyBookDao newDcBibliographyBookDao;

    @Resource
    private NewDcBibliographyPeriDao newDcBibliographyPeriDao;

    protected Long findBook(String bookName, String printIsbn, String onlineIsbn, Integer dataType) {
        if (!Strings.isNullOrEmpty(printIsbn)) {
            NewDcBibliographyBook oneByPISBN = newDcBibliographyBookDao.findOneByPISBN(printIsbn, dataType);
            if (oneByPISBN != null) {
                return oneByPISBN.getRecordId();
            }
        }
        if (!Strings.isNullOrEmpty(onlineIsbn)) {
            NewDcBibliographyBook oneByEISBN = newDcBibliographyBookDao.findOneByEISBN(onlineIsbn, dataType);
            if (oneByEISBN != null) {
                return oneByEISBN.getRecordId();
            }
        }
        if (!Strings.isNullOrEmpty(bookName)) {
            NewDcBibliographyBook oneByTitle = newDcBibliographyBookDao.findOneByTitle(bookName, dataType);
            if (oneByTitle != null) {
                return oneByTitle.getRecordId();
            }
        }
        return null;
    }

    protected Long findPeri(String periName, String pIssn, String cn, Integer dataType) {
        if (!Strings.isNullOrEmpty(pIssn)) {
            NewDcBibliographyPeri oneByPISSN = newDcBibliographyPeriDao.findOneByPISSN(pIssn, dataType);
            if (oneByPISSN != null) {
                return oneByPISSN.getRecordId();
            }
        }

        if (!Strings.isNullOrEmpty(cn)) {
            NewDcBibliographyPeri oneByCN = newDcBibliographyPeriDao.findOneByCN(cn);
            if (oneByCN != null) {
                return oneByCN.getRecordId();
            }
        }
        if (!Strings.isNullOrEmpty(periName)) {
            NewDcBibliographyPeri oneByTitle = newDcBibliographyPeriDao.findCnOneByTitle(periName, dataType);
            if (oneByTitle != null) {
                return oneByTitle.getRecordId();
            }
        }
        return null;
    }

    protected Long findUSPeri(String periName,String pIssn,String eIssn,Integer dataType){
        if (!Strings.isNullOrEmpty(pIssn)) {
            NewDcBibliographyPeri oneByPISSN = newDcBibliographyPeriDao.findOneByPISSN(pIssn, dataType);
            if (oneByPISSN != null) {
                return oneByPISSN.getRecordId();
            }
        }

        if (!Strings.isNullOrEmpty(eIssn)) {
            NewDcBibliographyPeri oneByeIssn = newDcBibliographyPeriDao.findOneByEISSN(eIssn);
            if (oneByeIssn != null) {
                return oneByeIssn.getRecordId();
            }
        }
        if (!Strings.isNullOrEmpty(periName)) {
            NewDcBibliographyPeri oneByTitle = newDcBibliographyPeriDao.findCnOneByTitle(periName,dataType);
            if (oneByTitle != null) {
                return oneByTitle.getRecordId();
            }
        }
        return null;
    }

}
